#version 300 es
precision mediump float;
out vec4 color;
in vec3 Normal;
in vec3 FragPos;
//in VS_OUT
//{
//    vec3 Normal;
//    vec3 FragPos;
//}fs_in;
//点光源位置
uniform vec3 lightPos;
uniform vec3 viewPos;
//点光源颜色
vec3 lightColor = vec3(1.0f, 1.0f, 1.0f);
void main() {
    vec4 objColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);
    //ambeint
    float ambeintStrength = 0.2f;       //光亮度
    vec3 ambeintLight = lightColor * ambeintStrength * vec3(objColor);
    //diffuse
    float diffuseStrength = 0.5f;
    vec3 lightDir = normalize(lightPos - FragPos);
    float diffuse = max(dot(lightDir, normalize(Normal)), 0.0f);
    vec3 diffuseLight = lightColor * diffuseStrength * diffuse * vec3(objColor);
    //specular
    float specularStrength = 1.0f;
    vec3 reflectDir = normalize(reflect(-lightDir, normalize(Normal)));
    vec3 viewDir = normalize(viewPos - FragPos);
    float specular = pow(max(dot(reflectDir, viewDir), 0.0f), 32.0f);
    vec3 specularLight = lightColor * specularStrength * specular * vec3(objColor);
    color = vec4(ambeintLight + diffuseLight + specularLight, 1.0f);
}
